package com.qdd.freight.service.impl;

import com.qdd.freight.config.HandlerContext;
import com.qdd.freight.entity.Datas;
import com.qdd.freight.handler.AbstractHandler;
import com.qdd.freight.service.QueryService;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName QueryServiceImpl
 * @Description TODO
 * @Author yanpeihao
 * @Date 2019/12/17 12:33
 * @Version 1.0
 **/
@Service
@Logger
public class QueryServiceImpl implements QueryService {

    //注入处理器容器
    @Autowired
    private HandlerContext handlerContext;

    /**
     * 快运方式查询
     *
     * @param modeId    快运类型
     * @param goodsId   商品id
     * @param entId     仓库id
     * @param quantity  采购数量
     * @param company   企业编号
     * @param consignee 省市区编号
     * @return
     */
    @Override
    public Datas query(Integer modeId, Integer goodsId, Integer entId, Integer quantity, Integer company,
                       String consignee, Double boxVolume, Double singleVolume, Double boxWeight,
                       Double singleWeight, Integer QTYRate) throws Exception {
        //从spring容器中获取处理器实例
        AbstractHandler handlerInstance = handlerContext.getHandlerInstance(String.valueOf(modeId));
        //实例对象调用自己继承并实现的方法获取所有支持的快运方式数据
        Datas datas = handlerInstance.realHandle(null, null, modeId, goodsId, entId, quantity, company, consignee,
                boxVolume, singleVolume, boxWeight, singleWeight, QTYRate);
        return datas;
    }
}
